import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/schooladmin.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/grids/studentsAddDatagrid.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';

class AddStudentsToClassSchoolAdminPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Log.debug('build schooladmin AddStudentsToClassPage');
    final box = Hive.box('appconfig');
    final SchoolAdminController _schoolAdminController = Get.find();

    bool isSchoolAdmin = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_SchoolAdmin;

    if (isSchoolAdmin) {
      String classId =
          _schoolAdminController.currentSchoolAdminClass.classId.toString();
      Future.delayed(Duration(milliseconds: 100), () {
        if (classId != '')
          _schoolAdminController
              .fetchAllStudentsNotInGivenClass(classId.toString());
      });
    }

    return Scaffold(
      appBar: CustomAppBar(title: 'Add Students'.tr),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            _schoolAdminController.obx(
                (data) => Expanded(
                    child: StudentsAddDataGrids(
                        true, _schoolAdminController.studentItemsNotInClass)),
                onEmpty: StudentsAddDataGrids(
                        true, _schoolAdminController.studentItemsNotInClass),
                ),
          ],
        ),
      ),
    );
  }
}
